package com.kaishengit.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.pojo.Filetype;
import com.kaishengit.pojo.Project;
import com.kaishengit.pojo.User;
import com.kaishengit.util.CreateTime;
import com.kaishengit.util.MyUUID;
import com.kaishengit.util.Outtime;

@Service
@Transactional
public class FiletypeService extends BaseService {
	
	public List<Filetype> getFiletypes(Project project) {
		
		List<Filetype> filetype = getFiletypeDao().findByProject(project);
		for (int i = 0; i < filetype.size(); i++) {
			filetype.get(i).setOuttime(
					Outtime.OutDateTime(filetype.get(i).getCreatetime()));
		}
		return filetype;
	}

	public void save(Filetype filetype, User user, Project project) {
		
		filetype.setId(MyUUID.createUUID().toString());
		filetype.setCreatetime(CreateTime.createTime());
		filetype.setUser(user);
		filetype.setProject(project);
		
		getFiletypeDao().save(filetype);
	}

	public Filetype findById(String id) {
		
		return getFiletypeDao().findById(id);
	}

	public void update(Filetype filetype, Project project, User user) {
		
		filetype.setCreatetime(CreateTime.createTime());
		filetype.setProject(project);
		filetype.setUser(user);
		getFiletypeDao().save(filetype);
		
	}
	
}
